package com.woniu.tms.interview.controller;

import java.util.HashMap;



import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.tms.entity.Companyinfo;
import com.woniu.tms.entity.Interview;
import com.woniu.tms.entity.User;
import com.woniu.tms.interview.service.InterviewService;

@Controller
@RequestMapping("work")
public class WorkController {
@Autowired
InterviewService interviewService;


@RequestMapping("companyindex")
@ResponseBody
public Map<String,Object> companyindex(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,@RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize,String info){
	Map<String,Object> map = new HashMap<>();
	try {
		PageHelper.startPage(pageNum, pageSize);
		List<Companyinfo> list = interviewService.finByUnameLike1(info);
		PageInfo<Companyinfo> pageInfo = new PageInfo<Companyinfo>(list);
		Integer unworkstudent = interviewService.UWB();
		Integer everworkstudent = interviewService.EWB();
		map.put("pageInfo", pageInfo);
		map.put("companyMesList", list);
	    map.put("result", true);
	    map.put("unworkstudent", unworkstudent);
	    map.put("everworkstudent", everworkstudent);
		
	}catch(Exception e) {
		e.printStackTrace();
		map.put("result", false);
	}
	return map;
}
@RequestMapping("companywithoutcaozuo")
@ResponseBody
public Map<String,Object> companywithoutcaozuo(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum,@RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize,String info){
	Map<String,Object> map = new HashMap<>();
	try {
		PageHelper.startPage(pageNum, pageSize);
		List<Companyinfo> list = interviewService.finByUnameLike1(info);
		PageInfo<Companyinfo> pageInfo = new PageInfo<Companyinfo>(list);
		Integer unworkstudent = interviewService.UWB();
		Integer everworkstudent = interviewService.EWB();
		map.put("pageInfo", pageInfo);
		map.put("companyMesList", list);
	    map.put("result", true);
	    map.put("unworkstudent", unworkstudent);
	    map.put("everworkstudent", everworkstudent);
		
	}catch(Exception e) {
		e.printStackTrace();
		map.put("result", false);
	}
	return map;
}
@RequestMapping("companyAdd")
@ResponseBody
public Map<String,Object> companyAdd(String companyName,String uphone,String uemail,String companyInfo,HttpSession session){
	Map<String,Object> map = new HashMap<>();
	try {
		User loginUser=(User) session.getAttribute("loginUser");
		interviewService.insert(companyName,uphone,uemail,companyInfo,loginUser);
		map.put("result", true);
	}catch(Exception e) {
		e.printStackTrace();
		map.put("result", false);
	}
	return map;
}

@RequestMapping("delOne")
@ResponseBody
public Map<String,Object> delOne(Integer companyid){
	Map<String,Object> map = new HashMap<>();
	try {
		interviewService.delOne(companyid);
		map.put("result", true);
	}catch(Exception e) {
		e.printStackTrace();
		map.put("result", false);
	}
	return map;
}
@RequestMapping("delAll")
@ResponseBody
public Map<String,Object> delAll(Integer[] uids){
	Map<String,Object> map = new HashMap<>();
	try {
		interviewService.delAll(uids);
		map.put("result", true);
	}catch(Exception e) {
		e.printStackTrace();
		map.put("result", false);
	}
	return map;
}
@RequestMapping("update")
@ResponseBody
public Map<String,Object> update(Integer companyid,String companyName,String companyInfo){
	Map<String,Object> map = new HashMap<>();
	try {
		interviewService.update(companyid,companyName,companyInfo);
		map.put("result", true);
	}catch(Exception e) {
		e.printStackTrace();
		map.put("result", false);
	}
	return map;
	
}
@RequestMapping("companyMes")
public String companyindex() {
	return "WEB-INF/interview/empinterview/companyindex";
}
@RequestMapping("companywithoutcaozuoindex")
public String companywithoutcauozuoindex() {
	return "WEB-INF/interview/teacherin/companywithoutcaozuo";
}







}
